using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Configuration;
using System.Threading;

namespace Musicman.Entities.BusinessEntities
{
    public class SearchJobConfigurationElement : ConfigurationElement 
    {
        public AutoResetEvent are;
    public int runningThreads = 0;

        public Guid jobID;

        [ConfigurationProperty("searchtype", IsRequired=true, DefaultValue=(byte)0)]
        public byte Stype
        {
            get { return (byte)this["searchtype"]; }// return (byte)stype; }
            set { this["searchtype"] = value; }
        }
        
        public DateTime timeStarted;
        
        public DateTime timeFinished;

        private string[] searchCriteria;

        public string[] SearchCriteria
        {
            get
            {
                if (this.searchCriteria == null)
                {
                    this.searchCriteria = this.AllCriteria.Split(';');
                }
                return this.searchCriteria;
            }
            set { searchCriteria = value; }
        }

        public long deletedFiles;

        public long addedFiles;

        public long modifiedFiles;
        
        public long totalFiles;
        
        public long totalSize;
        
        public long totalTime;
        
        public List<Searchlocation> searchResult;
        
        public AsyncOperation asyncOp = null;
        
        public Exception exception = null;

        [ConfigurationProperty("criteria", IsRequired=true)]
        public string AllCriteria
        {
            get { return (string)this["criteria"]; }// return allCriteria; }
            set 
            { 
                this["criteria"] = value;
            }
        }

        [ConfigurationProperty("name", IsRequired=true)]
        public string Name
        {
            get { return (string)this["name"]; } // return name; }
            set { this["name"] = value; }
        }
        
        public SearchFileCollection foundFiles;

        public SearchJobConfigurationElement()
        {
            searchResult = new List<Searchlocation>();
            this.foundFiles = new SearchFileCollection();
            this.are = new AutoResetEvent(false);
        }

        public SearchJobConfigurationElement(string criteria)
        {
            this.searchResult = new List<Searchlocation>();
            this.searchCriteria = criteria.Split(';');
            AllCriteria = criteria;
            this.foundFiles = new SearchFileCollection();
        }

        public SearchJobConfigurationElement(byte searchType, string name, string criteria)
        {
            Stype = searchType;
            Name = name;
            this.searchResult = new List<Searchlocation>();
            this.searchCriteria = criteria.Split(';');
            AllCriteria = criteria;
            this.foundFiles = new SearchFileCollection();
        }

        [ConfigurationProperty("minsize", IsRequired = false, DefaultValue = null)]
        public long? Minsize
        {
            get { return (long?)this["minsize"]; }
            set { this["minsize"] = value; }
        }

        [ConfigurationProperty("maxsize", IsRequired = false, DefaultValue = null)]
        public long? Maxsize
        {
            get { return (long?)this["maxsize"]; }
            set { this["maxsize"] = value; }
        }  

    }
    
    public enum SearchType : byte
    {
        Local,
        Network
    }
    
}
